<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增横幅广告')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-banner-add">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">[[#{titleName}]]：</label>
                    <div class="col-sm-8">
                        <input name="titleName" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                <label class="col-sm-3 control-label is-required">[[#{image}]]：</label>
                <div class="col-sm-8">
                    <div class="fileinput fileinput-new" data-provides="fileinput">
                        <div class="fileinput-new thumbnail" style="width: 120px;">
                            <img th:src="@{/img/nopic.jpg}">
                        </div>
                        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 450px;"></div>
                        <div>
                    <span class="btn btn-white btn-file"><span class="fileinput-new">[[#{select.img}]]</span><span class="fileinput-exists">[[#{change}]]</span>
                    <input type="file" id="img-file" accept="image/*" required></span>
                            <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">[[#{clear}]]</a>
                        </div>
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>[[#{suggest.img.size}]]</span>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">产品id：</label>
                    <div class="col-sm-8">
                        <input name="productId" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{linkUrl}]]：</label>
                    <div class="col-sm-8">
                        <input name="linkUrl" class="form-control" type="text" th:placeholder="#{linkUrl}">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">[[#{status}]]：</label>
                    <div class="col-sm-8">
                        <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                            <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                            <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:inline="javascript">
        var prefix = ctx + "product/banner"
        $("#form-banner-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                //$.operate.save(prefix + "/add", $('#form-banner-add').serialize());

                submitData(prefix + "/add", $('#form-banner-add').serializeObject(), 1);
            }
        }


        $.fn.serializeObject = function()
        {
            var o = new FormData();
            var formArray = this.serializeArray();
            $.each(formArray, function() {

                o.append(this.name+'', (this.value || ''));
            });
            return o;
        };

        function submitData(url, formData, type) {
            var file = $('#img-file')[0].files[0];

            if (file == undefined || file == null) {
                $.modal.alertWarning(i18n('select.img'));
                return;
            }

            if(file != undefined){
                var fileSize = parseInt(file.size / 1024); //KB
                if(fileSize > 1024 *5){
                    var sizeTips = i18n('select.img.size');
                    $.modal.alertWarning( sizeTips.replace("{0}", fileSize));
                    return;
                }
            }
            formData.append('file', file);

            $.ajax({
                url: url,
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    if(1 == type) {
                        $.operate.successCallback(result);
                    } else {
                        //提交后不刷新清空；
                        if (result && result.code == 0) {
                            $.modal.msgSuccess(result.msg);

                            emptyFrom();
                        } else {
                            $.modal.alertError(result.msg);
                        }
                    }
                }
            });
        }
    </script>
    <script th:inline="javascript">
        //获取应用路径
        var ROOT = [[${#servletContext.contextPath}]];

        //获取默认语言
        var LANG_COUNTRY = [[${#locale.language+'_'+#locale.country}]];

        //初始化i18n插件
        $.i18n.properties({
            path: ROOT + '/i18n/',//这里表示访问路径
            name: 'messages',//文件名开头
            language: LANG_COUNTRY,//文件名语言 例如en_US
            mode: 'map'//默认值
        });

        //初始化i18n函数
        function i18n(msgKey) {
            try {
                return $.i18n.prop(msgKey);
            } catch (e) {
                return msgKey;
            }
        }

        //获取国际化翻译值
        //console.log(i18n('supplier.name'));
    </script>
</body>
</html>